package com.ruoyi.system.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.*;
import com.ruoyi.common.pojo.*;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.system.mapper.*;
import com.ruoyi.system.service.SysTaskService;
import com.ruoyi.web.service.DeviceService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author syj
 * @description 针对表【sys_task(任务表)】的数据库操作Service实现
 * @createDate 2022-08-23 14:32:36
 */
@Slf4j
@Service
public class SysTaskServiceImpl extends ServiceImpl<SysTaskMapper, SysTask> implements SysTaskService {

    @Resource
    SysTaskMapper sysTaskMapper;

    @Resource
    SysTaskFileMapper sysTaskFileMapper;

    @Resource
    SysTaskRouteMapper sysTaskRouteMapper;

    @Resource
    SysCruiseMapper sysCruiseMapper;

    @Resource
    SysRouteMapper sysRouteMapper;

    @Resource
    SysTaskPlanrouteMapper sysTaskPlanrouteMapper;

    @Resource
    SysRouteAxesMapper sysRouteAxesMapper;

    @Resource
    SysTaskCycleMapper sysTaskCycleMapper;

    @Resource
    SysTaskPlanMapper sysTaskPlanMapper;

    @Resource
    SysTaskPlanDetailMapper sysTaskPlanDetailMapper;

    @Resource
    SysTaskIssueMapper sysTaskIssueMapper;

    @Resource
    SysIssueTypeMapper sysIssueTypeMapper;

    @Resource
    SysUserMapper sysUserMapper;

    @Resource
    SysDeviceInfoMapper sysDeviceInfoMapper;

    @Resource
    SysCruiseDeviceMapper sysCruiseDeviceMapper;

    @Resource
    SysDeviceTypeMapper sysDeviceTypeMapper;

    @Resource
    SysTaskRecordMapper sysTaskRecordMapper;

    @Resource
    SysTaskRecordIssueMapper sysTaskRecordIssueMapper;

    @Resource
    SysResMapper sysResMapper;

    @Resource
    SysTaskRecordFileMapper sysTaskRecordFileMapper;

    @Qualifier("threadPoolTaskExecutor")
    @Autowired
    ThreadPoolTaskExecutor executor;

    @Resource
    DeviceService deviceService;


    @Override
    public AjaxResult changeBoatDirection(BoatDirectionParam param) {
        return AjaxResult.success();
    }

    @Override
    @Transactional(rollbackFor = {Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public AjaxResult switchTaskModel(SysTask param) {
        SysTask sysTask = sysTaskMapper.selectOne(Wrappers.<SysTask>lambdaQuery().eq(SysTask::getId, param.getId()));
        if (Objects.isNull(sysTask)) {
            return AjaxResult.error("任务不存在");
        }

        sysTask.setUserSpecifiedSpeed(param.getUserSpecifiedSpeed());
        sysTask.setModelType(param.getModelType());
        sysTask.setPlanRouteId(param.getPlanRouteId());

        sysTaskMapper.updateById(sysTask);
        if (ObjectUtil.isNotNull(param.getPlanRouteId())) {
            SysTaskPlanroute sysTaskPlanroute = new SysTaskPlanroute();
            sysTaskPlanroute.setPlanId(param.getPlanRouteId());
            sysTaskPlanroute.setTaskId(param.getId());
            sysTaskPlanroute.setCreateTime(DateUtil.date());
            sysTaskPlanrouteMapper.insert(sysTaskPlanroute);
        }
        return AjaxResult.success();
    }

    @Override
    @Transactional(rollbackFor = {Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public AjaxResult createTask(SysTask param) {

        Integer type = param.getType();
        if (type == 2) {
            List<SysTask> sysTasks = sysTaskMapper.selectList(Wrappers.<SysTask>lambdaQuery().eq(SysTask::getFinish, 0).eq(SysTask::getObjectId, param.getObjectId()).eq(SysTask::getType, 2));
            if (Objects.nonNull(sysTasks) && !sysTasks.isEmpty() && sysTasks.size() > 0) {
                return AjaxResult.error("当前设备已经在任务中");
            }
            //由于目前只有一条船，所以暂时限制只有有一个经行中的巡河任务
            List<SysTask> sysTasks1 = sysTaskMapper.selectList(Wrappers.<SysTask>lambdaQuery().eq(SysTask::getFinish, 0).eq(SysTask::getType, 2));
            if (Objects.nonNull(sysTasks1) && !sysTasks1.isEmpty() && sysTasks1.size() > 0) {
                return AjaxResult.error("当前设备已经在任务中");
            }
        }

        DateTime nowDate = DateUtil.date();
        SysTask sysTask = SysTask.builder()
                .finish(0)
                .state(1)
                .type(type)
                .userId(param.getUserId())
                .createTime(nowDate)
                .objectId(param.getObjectId())
                .planRouteId(param.getPlanRouteId())
                .modelType(param.getModelType())
                .build();

        if (ObjectUtil.isNotNull(param.getPlanId())) {
            SysTaskPlan sysTaskPlan = sysTaskPlanMapper.selectOne(Wrappers.<SysTaskPlan>lambdaQuery()
                    .eq(SysTaskPlan::getId, param.getPlanId())
            );
            if (ObjectUtil.isNotNull(sysTaskPlan)) {
                if (sysTaskPlan.getFinish().intValue() == 0 && sysTaskPlan.getState().intValue() == 1) {
                    if (sysTaskPlan.getFlowpath().intValue() == 2 && nowDate.isBefore(sysTaskPlan.getEndTime())) {
                        sysTask.setPlanId(param.getPlanId());
                    }
                }
            }
        }
        sysTaskMapper.insert(sysTask);

        if (ObjectUtil.isNotNull(param.getPlanRouteId())) {
            SysTaskPlanroute sysTaskPlanroute = new SysTaskPlanroute();
            sysTaskPlanroute.setPlanId(param.getPlanRouteId());
            sysTaskPlanroute.setTaskId(sysTask.getId());
            sysTaskPlanroute.setCreateTime(nowDate);
            sysTaskPlanrouteMapper.insert(sysTaskPlanroute);
        }

        PushTaskIdVO pushTaskIdVO = new PushTaskIdVO();
        pushTaskIdVO.setTaskId(sysTask.getId());
        deviceService.sendMessage("newTask", pushTaskIdVO);
        return AjaxResult.success(sysTask.getId());
    }

    @Override
    @Transactional(rollbackFor = {Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public AjaxResult closeTask(SysTask param) {

        SysTask sysTask = sysTaskMapper.selectOne(Wrappers.<SysTask>lambdaQuery().eq(SysTask::getId, param.getId()));
        if (ObjectUtil.isNotNull(sysTask)) {
            if (sysTask.getState().intValue() == 1 && sysTask.getFinish().intValue() == 0) {
                Date nowDate = DateUtils.getNowDate();
                SysTask task = SysTask.builder()
                        .finish(1)
                        .endTime(nowDate)
                        .build();
                sysTaskMapper.update(task, Wrappers.<SysTask>lambdaUpdate()
                        .eq(SysTask::getId, param.getId())
                        .eq(SysTask::getFinish, 0)
                );
                if (Objects.nonNull(sysTask.getPlanId())) {
                    SysTaskPlanDetail sysTaskPlanDetail = SysTaskPlanDetail.builder()
                            .finish(1)
                            .build();
                    sysTaskPlanDetailMapper.update(sysTaskPlanDetail, Wrappers.<SysTaskPlanDetail>lambdaUpdate()
                            .eq(SysTaskPlanDetail::getPlanId, sysTask.getPlanId())
                            .eq(SysTaskPlanDetail::getUserId, SecurityUtils.getUserId())
                            .eq(SysTaskPlanDetail::getState, 1)
                            .eq(SysTaskPlanDetail::getFinish, 0)
                    );
                    List<SysTaskPlanDetail> sysTaskPlanDetails = sysTaskPlanDetailMapper.selectList(Wrappers.<SysTaskPlanDetail>lambdaQuery()
                            .eq(SysTaskPlanDetail::getPlanId, sysTask.getPlanId())
                            .eq(SysTaskPlanDetail::getState, 1)
                    );
                    Long finishCount = sysTaskPlanDetails.stream().filter(v -> v.getFinish().intValue() == 1).count();
                    if (finishCount.intValue() == sysTaskPlanDetails.size()) {
                        SysTaskPlan sysTaskPlan = sysTaskPlanMapper.selectOne(Wrappers.<SysTaskPlan>lambdaQuery()
                                .eq(SysTaskPlan::getId, task.getPlanId())
                        );

                        if (ObjectUtil.isNotNull(sysTaskPlan)) {
                            if (sysTaskPlan.getState().intValue() == 1 && sysTaskPlan.getFinish().intValue() == 0) {
                                SysTaskPlan taskPlan = new SysTaskPlan();
                                taskPlan.setFinish(1);
                                taskPlan.setStopTime(nowDate);
                                sysTaskPlanMapper.update(taskPlan, Wrappers.<SysTaskPlan>lambdaUpdate()
                                        .eq(SysTaskPlan::getId, task.getPlanId())
                                );
                            }
                        }
                    }
                }
                return AjaxResult.success(sysTask.getId());
            } else {
                return AjaxResult.error("巡河已结束");
            }
        }

        return AjaxResult.error("巡河不存在");
    }

    @Override
    public AjaxResult switchPlanRoute(SwitchPlanRouteReq param) {
        SysTaskPlanroute sysTaskPlanroute = new SysTaskPlanroute();
        sysTaskPlanroute.setPlanId(param.getPlanRouteId());
        sysTaskPlanroute.setTaskId(param.getTaskId());
        sysTaskPlanroute.setCreateTime(DateUtil.date());
        sysTaskPlanrouteMapper.insert(sysTaskPlanroute);
        return AjaxResult.success();
    }

    @Override
    public AjaxResult uploadTrack(SysTaskRoute param) {
        DateTime now = DateUtil.date();
        SysTaskRoute sysTaskRoute = SysTaskRoute.builder()
                .taskId(param.getTaskId())
                .latitude(param.getLatitude())
                .longitude(param.getLongitude())
                .sort(param.getSort())
                .createTime(now)
                .build();
        sysTaskRouteMapper.insert(sysTaskRoute);
        SysTask task = getById(param.getTaskId());
        SysTask sysTask = new SysTask();
        long counttime = DateUtil.betweenMs(task.getCreateTime(), now) / 1000;
        sysTask.setCounttime(counttime);
        sysTask.setCountdistance(param.getCountdistance());
        sysTaskMapper.update(sysTask, Wrappers.<SysTask>lambdaUpdate()
                .eq(SysTask::getId, param.getTaskId())
                .eq(SysTask::getState, 1)
                .eq(SysTask::getFinish, 0)
        );
        return AjaxResult.success();
    }

    @Override
    @Transactional(rollbackFor = {Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public AjaxResult addIssue(SysTaskIssue param) {
        param.setAuditStatus(0);
        param.setStatus(1);
        sysTaskIssueMapper.insert(param);
        List<SysTaskFile> file = param.getFile();
        if (CollUtil.isNotEmpty(file)) {
            for (SysTaskFile sysTaskFile : file) {
                sysTaskFile.setTaskId(param.getTaskId());
                sysTaskFileMapper.insert(sysTaskFile);
            }
        }
        return AjaxResult.success();
    }

    @Override
    public AjaxResult getIssue(GetTaskIssueReq param) {
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        List<SysTaskIssue> sysTaskIssues = sysTaskIssueMapper.selectList(Wrappers.<SysTaskIssue>lambdaQuery()
                .eq(ObjectUtil.isNotNull(param.getTaskId()), SysTaskIssue::getTaskId, param.getTaskId())
                .eq(ObjectUtil.isNotNull(param.getPlanId()), SysTaskIssue::getPlanId, param.getPlanId())
                .eq(ObjectUtil.isNotNull(param.getIssueTypeId()), SysTaskIssue::getIssueTypeId, param.getIssueTypeId())
                .eq(ObjectUtil.isNotNull(param.getSeverity()), SysTaskIssue::getSeverity, param.getSeverity())
                .eq(ObjectUtil.isNotNull(param.getAuditStatus()), SysTaskIssue::getAuditStatus, param.getAuditStatus())
                .eq(SysTaskIssue::getStatus, 1)
        );

        List<SysIssueType> sysIssueTypes = sysIssueTypeMapper.selectList(Wrappers.<SysIssueType>lambdaQuery());
        for (SysTaskIssue sysTaskIssue : sysTaskIssues) {
            List<SysTaskFile> sysTaskFiles = sysTaskFileMapper.selectList(Wrappers.<SysTaskFile>lambdaQuery()
                    .eq(SysTaskFile::getTaskId, sysTaskIssue.getTaskId())
                    .eq(SysTaskFile::getState, 1)
            );
            if (CollUtil.isNotEmpty(sysTaskFiles)) {
                sysTaskIssue.setFile(sysTaskFiles);
            }
            SysIssueType sysIssueType = sysIssueTypes.stream().filter(v -> StrUtil.equals(String.valueOf(v.getId()), sysTaskIssue.getIssueTypeId())).findAny().get();
            if (ObjectUtil.isNotNull(sysIssueType)) {
                sysTaskIssue.setIssueTypeName(sysIssueType.getIssueType());
            }
        }

        PageInfo<SysTaskIssue> pageInfo = new PageInfo<SysTaskIssue>(sysTaskIssues);
        return AjaxResult.success(pageInfo);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public AjaxResult deleteIssue(Long issueId) {
        SysTaskIssue sysTaskIssue = sysTaskIssueMapper.selectOne(Wrappers.<SysTaskIssue>lambdaQuery().eq(SysTaskIssue::getId, issueId));
        if (ObjectUtil.isNotNull(sysTaskIssue)) {
            SysTaskIssue newSysTaskIssue = new SysTaskIssue();
            newSysTaskIssue.setStatus(0);
            sysTaskIssueMapper.update(newSysTaskIssue, Wrappers.<SysTaskIssue>lambdaUpdate().eq(SysTaskIssue::getId, issueId));

            SysTaskFile sysTaskFile = new SysTaskFile();
            sysTaskFile.setState(0);
            sysTaskFileMapper.update(sysTaskFile, Wrappers.<SysTaskFile>lambdaUpdate().eq(SysTaskFile::getTaskId, issueId));
        }
        return AjaxResult.success();
    }

    @Override
    @Transactional(rollbackFor = {Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public AjaxResult updateIssue(SysTaskIssue param) {
        sysTaskIssueMapper.updateById(param);
        List<SysTaskFile> file = param.getFile();
        SysTaskFile sysTaskFile = new SysTaskFile();
        sysTaskFile.setState(0);
        sysTaskFileMapper.update(sysTaskFile, Wrappers.<SysTaskFile>lambdaUpdate().eq(SysTaskFile::getTaskId, param.getTaskId()));
        if (CollUtil.isNotEmpty(file)) {
            for (SysTaskFile taskFile : file) {
                taskFile.setTaskId(param.getTaskId());
                sysTaskFileMapper.insert(taskFile);
            }
        }
        return AjaxResult.success();
    }

    @Override
    public AjaxResult getIssueTypeList() {
        List<SysIssueType> sysIssueTypes = sysIssueTypeMapper.selectList(Wrappers.<SysIssueType>lambdaQuery());
        return AjaxResult.success(sysIssueTypes);
    }

    @Override
    public AjaxResult uploadFile(MultipartFile file, Integer type) {
        String path = null;
        try {
            path = FileUploadUtils.upload(RuoYiConfig.getTaskPath(), file);
            SysRes sysRes = new SysRes();
            sysRes.setUserId(SecurityUtils.getUserId());
            sysRes.setCreateTime(DateUtil.date());
            sysRes.setState(1);
            sysRes.setFilePath(path);
            sysRes.setFileType(type);
            sysResMapper.insert(sysRes);
            return AjaxResult.success(sysRes.getId());
        } catch (Exception e) {
            log.error("上传文件失败", e);
        }
        return AjaxResult.error("上传文件失败");
    }

    @Override
    public AjaxResult getFile(Long id) {
        SysRes sysRes = sysResMapper.selectById(id);
        return AjaxResult.success(sysRes);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public AjaxResult deleteTrack(SysTask param) {

        SysTask sysTask = sysTaskMapper.selectOne(Wrappers.<SysTask>lambdaQuery().eq(SysTask::getId, param.getId()));
        if (ObjectUtil.isNotNull(sysTask)) {
            SysTask task = SysTask.builder()
                    .state(0)
                    .build();
            sysTaskMapper.update(task, Wrappers.<SysTask>lambdaUpdate().eq(SysTask::getId, param.getId()));
        }

        return AjaxResult.success();
    }

    @Override
    public AjaxResult deleteFile(SysTaskFile param) {

        SysTaskFile sysTaskFile = SysTaskFile.builder()
                .taskId(param.getTaskId())
                .id(param.getId())
                .state(0)
                .build();
        sysTaskFileMapper.updateById(sysTaskFile);
        return AjaxResult.success();
    }

    @Override
    public AjaxResult queryTaskList(QueryTaskListReq param) {
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        DateTime endOfDay = null;
        if (StringUtils.isNotBlank(param.getEndTime())) {
            endOfDay = DateUtil.endOfDay(DateUtils.parseDate(param.getEndTime()));
        }
        List<SysTask> sysTasks = sysTaskMapper.selectList(Wrappers.<SysTask>lambdaQuery()
                .eq(SysTask::getState, 1)
                .eq(Objects.nonNull(param.getFinish()), SysTask::getFinish, param.getFinish())
                .eq(Objects.nonNull(param.getType()), SysTask::getType, param.getType())
                .eq(Objects.nonNull(param.getUserId()), SysTask::getUserId, param.getUserId())
                .ge(StringUtils.isNotBlank(param.getStartTime()), SysTask::getCreateTime, DateUtils.parseDate(param.getStartTime()))
                .le(StringUtils.isNotBlank(param.getEndTime()), SysTask::getCreateTime, endOfDay)
                .like(StringUtils.isNotBlank(param.getName()), SysTask::getName, param.getName())
                .orderByDesc(SysTask::getCreateTime)
        );

        sysTasks.forEach(v -> {

            v.setName(v.getName());
            SysUser sysUser = sysUserMapper.selectUserById(v.getUserId());
            v.setUserName(sysUser.getUserName());
            v.setName(sysUser.getUserName() + "的巡河任务");

            //List<SysTaskRoute> sysTaskRoutes = sysTaskRouteMapper.selectList(Wrappers.<SysTaskRoute>lambdaQuery()
            //        .eq(SysTaskRoute::getTaskId, v.getId())
            //);

            //v.setTaskRoutes(sysTaskRoutes);

            if (v.getType() == 1) {

                List<SysTaskFile> sysTaskFiles = sysTaskFileMapper.selectList(Wrappers.<SysTaskFile>lambdaQuery()
                        .eq(SysTaskFile::getTaskId, v.getId())
                        .eq(SysTaskFile::getState, 1)
                );
                v.setTaskFiles(sysTaskFiles);

            } else if (v.getType() == 2) {
                if (Objects.nonNull(v.getObjectId())) {
                    SysCruise sysCruises = sysCruiseMapper.selectOne(Wrappers.<SysCruise>lambdaQuery().eq(SysCruise::getId, v.getObjectId()));
                    if (Objects.nonNull(sysCruises)) {
                        ArrayList<SysDeviceInfo> devicelist = new ArrayList<>();
                        List<SysCruiseDevice> sysCruiseDevices = sysCruiseDeviceMapper.selectList(Wrappers.<SysCruiseDevice>lambdaQuery().eq(SysCruiseDevice::getCruiseId, sysCruises.getId()));
                        if (!sysCruiseDevices.isEmpty()) {
                            for (SysCruiseDevice sysCruiseDevice : sysCruiseDevices) {
                                SysDeviceInfo sysDeviceInfo = sysDeviceInfoMapper.selectOne(Wrappers.<SysDeviceInfo>lambdaQuery().eq(SysDeviceInfo::getId, sysCruiseDevice.getDeviceId()));
                                if (Objects.nonNull(sysDeviceInfo)) {
                                    SysDeviceType sysDeviceType = sysDeviceTypeMapper.selectOne(Wrappers.<SysDeviceType>lambdaQuery().eq(SysDeviceType::getDeviceType, sysDeviceInfo.getDeviceType()));
                                    sysDeviceInfo.setDeviceTypeName(sysDeviceType.getName());
                                    devicelist.add(sysDeviceInfo);
                                }
                            }
                            sysCruises.setDevicelist(devicelist);
                        }
                    }
                    v.setCruise(sysCruises);
                }

                List<SysTaskPlanroute> sysTaskPlanrouteList = sysTaskPlanrouteMapper.selectList(Wrappers.<SysTaskPlanroute>lambdaQuery().eq(SysTaskPlanroute::getTaskId, v.getId()).orderByAsc(SysTaskPlanroute::getCreateTime));
                for (SysTaskPlanroute sysTaskPlanroute : sysTaskPlanrouteList) {
                    SysRoute sysRoute = sysRouteMapper.selectOne(Wrappers.<SysRoute>lambdaQuery().eq(SysRoute::getId, sysTaskPlanroute.getPlanId()));
                    if (Objects.nonNull(sysRoute)) {
                        List<SysRouteAxes> sysRouteAxesList = sysRouteAxesMapper.selectList(Wrappers.<SysRouteAxes>lambdaQuery().eq(SysRouteAxes::getState, 1).eq(SysRouteAxes::getRoute, sysRoute.getId()));
                        sysRoute.setRouteAxesList(sysRouteAxesList);
                        sysTaskPlanroute.setSysRoute(sysRoute);
                    }
                }
                v.setSysTaskPlanrouteList(sysTaskPlanrouteList);
            }
        });

        PageInfo<SysTask> pageInfo = new PageInfo<SysTask>(sysTasks);
        return AjaxResult.success(pageInfo);
    }

    @Override
    public AjaxResult getTaskRoute(SysTask param) {
        List<SysTaskRoute> sysTaskRoutes = sysTaskRouteMapper.selectList(Wrappers.<SysTaskRoute>lambdaQuery()
                .eq(SysTaskRoute::getTaskId, param.getId())
        );
        return AjaxResult.success(sysTaskRoutes);
    }

    public AjaxResult getTaskList(GetTaskListReq param) {
        List<SysTask> sysTasks = sysTaskMapper.selectList(Wrappers.<SysTask>lambdaQuery().eq(SysTask::getState, 1));

        List<SysTask> event = new ArrayList<>();
        List<SysTask> finish = sysTasks.stream().filter(u -> u.getFinish() == 1).collect(Collectors.toList());

        GetTaskListRes getTaskListRes = GetTaskListRes
                .builder()
                .totalTask(sysTasks.size())
                .finishTask(finish.size())
                .eventTask(event.size())
                .noEventTask(sysTasks.size() - event.size())
                .noFinishTask(sysTasks.size() - finish.size())
                .build();
        return AjaxResult.success(getTaskListRes);
    }

    @Override
    public AjaxResult startUserPatrolRiver(StartUserPatrolRiverReq param) {
        Long userId = SecurityUtils.getUserId();
        List<SysTask> sysTasks = sysTaskMapper.selectList(Wrappers.<SysTask>lambdaQuery()
                .eq(SysTask::getUserId, userId)
                .ne(SysTask::getFinish, 1)
        );
        if (CollUtil.isNotEmpty(sysTasks)) {
            return AjaxResult.error("请完成暂停的巡河");
        }

        SysTask sysTask = SysTask.builder()
                .userId(userId)
                .finish(0)
                .counttime(0L)
                .createTime(DateUtil.date())
                .state(1)
                .type(1)
                .planId(param.getPlanId())
                .countdistance(0L)
                .counttime(0L)
                .objectId(userId.intValue())
                .build();
        save(sysTask);
        return AjaxResult.success(sysTask.getId());
    }

    @Override
    public AjaxResult pauseUserPatrolRiver(PauseUserPatrolRiverReq param) {
        SysTask sysTask = new SysTask();
        sysTask.setFinish(2);
        sysTask.setUpdateTime(DateUtil.date());
        sysTask.setReviseId(SecurityUtils.getUserId());
        boolean update = update(sysTask, Wrappers.<SysTask>lambdaQuery().eq(SysTask::getId, param.getId()));
        return AjaxResult.success(update);
    }

    @Override
    public AjaxResult restoreUserPatrolRiver(PauseUserPatrolRiverReq param) {
        SysTask sysTask = new SysTask();
        sysTask.setFinish(0);
        sysTask.setUpdateTime(DateUtil.date());
        sysTask.setReviseId(SecurityUtils.getUserId());
        boolean update = update(sysTask, Wrappers.<SysTask>lambdaQuery().eq(SysTask::getId, param.getId()));
        return AjaxResult.success(update);
    }

    @Override
    public AjaxResult stopUserPatrolRiver(PauseUserPatrolRiverReq param) {
        SysTask sysTask = getById(param.getId());
        if (Objects.nonNull(sysTask) && sysTask.getState().intValue() == 1) {
            if (sysTask.getFinish().intValue() != 1) {
                if (sysTask.getCounttime() >= 20 && sysTask.getCountdistance().intValue() >= 10) {
                    DateTime now = DateUtil.date();
                    SysTask updateSysTask = new SysTask();
                    updateSysTask.setFinish(1);
                    updateSysTask.setEndTime(now);
                    long counttime = DateUtil.betweenMs(sysTask.getCreateTime(), now) / 1000;
                    updateSysTask.setCounttime(counttime);
                    boolean update = update(updateSysTask, Wrappers.<SysTask>lambdaQuery().eq(SysTask::getId, param.getId()));
                    return AjaxResult.success(update);
                }
                return AjaxResult.error("停止巡河失败,未超过最短巡河长度和最小巡河时长");
            }
            return AjaxResult.error("巡河已结束");
        }
        return AjaxResult.error("非法操作");
    }

    @Override
    @Transactional(rollbackFor = {Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public AjaxResult addUserPatrolRiverRecord(AddUserPatrolRiverRecordReq param) {

        if (ObjectUtil.isNull(param.getHasProblem())) {
            return AjaxResult.error("hasProblem不能为空");
        }

        if (param.getHasProblem().intValue() == 0 && CollUtil.isNotEmpty(param.getIssues())) {
            return AjaxResult.error("不存在事件,问题类型必须为空");
        }

        if (param.getHasProblem().intValue() == 1 && CollUtil.isEmpty(param.getIssues())) {
            return AjaxResult.error("存在事件,问题类型不能为空");
        }

        Long userId = SecurityUtils.getUserId();
        DateTime now = DateUtil.date();
        SysTaskRecord sysTaskRecord = new SysTaskRecord();
        sysTaskRecord.setTaskId(param.getTaskId());
        sysTaskRecord.setProblem(param.getHasProblem());
        sysTaskRecord.setContent(param.getContent());
        sysTaskRecord.setCreateTime(now);
        sysTaskRecord.setState(1);
        sysTaskRecord.setLatitude(param.getLatitude());
        sysTaskRecord.setLongitude(param.getLongitude());
        sysTaskRecord.setUserId(userId);
        int insert = sysTaskRecordMapper.insert(sysTaskRecord);

        List<Integer> issues = param.getIssues();
        if (CollUtil.isNotEmpty(issues)) {
            SysTaskRecordIssue sysTaskRecordIssue = null;
            for (Integer issueTypeId : issues) {
                sysTaskRecordIssue = new SysTaskRecordIssue();
                sysTaskRecordIssue.setRecordId(sysTaskRecord.getId());
                sysTaskRecordIssue.setIssueTypeId(issueTypeId);
                sysTaskRecordIssue.setCreateTime(now);
                sysTaskRecordIssue.setIssueState(0);
                sysTaskRecordIssue.setExamineState(0);
                sysTaskRecordIssue.setState(1);
                sysTaskRecordIssueMapper.insert(sysTaskRecordIssue);
            }
        }

        List<Long> files = param.getFiles();
        if (CollUtil.isNotEmpty(files)) {
            SysTaskRecordFile sysTaskRecordFile = null;
            for (Long fileId : files) {
                sysTaskRecordFile = new SysTaskRecordFile();
                sysTaskRecordFile.setState(1);
                sysTaskRecordFile.setCreateTime(now);
                sysTaskRecordFile.setResId(fileId);
                sysTaskRecordFile.setRecordId(sysTaskRecord.getId());
                sysTaskRecordFileMapper.insert(sysTaskRecordFile);
            }
        }

        return AjaxResult.success(SqlHelper.retBool(insert));
    }

    @Override
    public AjaxResult getUserPatrolRiverRecordDetail(Long id) {
        List<SysTaskRecord> sysTaskRecordList = sysTaskRecordMapper.selectList(Wrappers.<SysTaskRecord>lambdaQuery()
                .eq(SysTaskRecord::getId, id)
                .eq(SysTaskRecord::getState, 1)
        );

        List<SysIssueType> sysIssueTypes = sysIssueTypeMapper.selectList(Wrappers.lambdaQuery());
        for (SysTaskRecord sysTaskRecord : sysTaskRecordList) {
            Long recordId = sysTaskRecord.getId();
            List<SysTaskRecordFile> sysTaskRecordFiles = sysTaskRecordFileMapper.selectList(Wrappers.<SysTaskRecordFile>lambdaQuery()
                    .eq(SysTaskRecordFile::getRecordId, recordId)
                    .eq(SysTaskRecordFile::getState, 1)
            );
            List<Long> fileIds = sysTaskRecordFiles.stream().map(SysTaskRecordFile::getId).collect(Collectors.toList());
            if (CollUtil.isNotEmpty(fileIds)) {
                List<SysRes> recordFile = sysResMapper.selectBatchIds(fileIds);
                sysTaskRecord.setRecordFile(recordFile);
            }

            List<SysTaskRecordIssue> sysTaskRecordIssueList = sysTaskRecordIssueMapper.selectList(Wrappers.<SysTaskRecordIssue>lambdaQuery()
                    .eq(SysTaskRecordIssue::getRecordId, recordId)
                    .eq(SysTaskRecordIssue::getState, 1)
            );
            List<SysIssueType> recordIssue = new ArrayList<>();
            if (CollUtil.isNotEmpty(sysTaskRecordIssueList)) {
                for (SysTaskRecordIssue sysTaskRecordIssue : sysTaskRecordIssueList) {
                    SysIssueType sysIssueType = sysIssueTypes.stream().filter(v -> StringUtils.equals(v.getId().toString(), sysTaskRecordIssue.getIssueTypeId().toString())).findAny().orElse(null);
                    if (Objects.nonNull(sysIssueType)) {
                        recordIssue.add(sysIssueType);
                    }
                }
            }
            sysTaskRecord.setRecordIssue(recordIssue);
        }

        return AjaxResult.success(sysTaskRecordList);
    }

    @Override
    public AjaxResult getMyUserPatrolRiverRecord(Integer issuestate, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<SysTaskRecord> sysTaskRecordList = sysTaskRecordMapper.selectList(Wrappers.<SysTaskRecord>lambdaQuery()
                .eq(SysTaskRecord::getState, 1)
                .eq(Objects.nonNull(issuestate), SysTaskRecord::getProblem, 1)
                .eq(SysTaskRecord::getUserId, SecurityUtils.getUserId())
        );
        if (Objects.nonNull(issuestate)) {
            List<Long> recordIdList = sysTaskRecordList.stream().map(SysTaskRecord::getId).collect(Collectors.toList());
            if (CollUtil.isNotEmpty(recordIdList)) {
                List<SysTaskRecordIssue> sysTaskRecordIssues = sysTaskRecordIssueMapper.selectList(Wrappers.<SysTaskRecordIssue>lambdaQuery()
                        .eq(SysTaskRecordIssue::getState, 1)
                        .eq(SysTaskRecordIssue::getIssueState, issuestate)
                        .in(SysTaskRecordIssue::getRecordId, recordIdList)
                );
                Set<Long> recordIdSet = sysTaskRecordIssues.stream().map(SysTaskRecordIssue::getRecordId).collect(Collectors.toSet());
                sysTaskRecordList = sysTaskRecordList.stream().filter(v -> recordIdSet.contains(v.getId())).collect(Collectors.toList());
            }
        }

        List<SysIssueType> sysIssueTypes = sysIssueTypeMapper.selectList(Wrappers.lambdaQuery());
        for (SysTaskRecord sysTaskRecord : sysTaskRecordList) {
            Long recordId = sysTaskRecord.getId();
            List<SysTaskRecordFile> sysTaskRecordFiles = sysTaskRecordFileMapper.selectList(Wrappers.<SysTaskRecordFile>lambdaQuery()
                    .eq(SysTaskRecordFile::getRecordId, recordId)
                    .eq(SysTaskRecordFile::getState, 1)
            );
            List<Long> fileIds = sysTaskRecordFiles.stream().map(SysTaskRecordFile::getResId).collect(Collectors.toList());
            if (CollUtil.isNotEmpty(fileIds)) {
                List<SysRes> recordFile = sysResMapper.selectBatchIds(fileIds);
                sysTaskRecord.setRecordFile(recordFile);
            }

            List<SysTaskRecordIssue> sysTaskRecordIssueList = sysTaskRecordIssueMapper.selectList(Wrappers.<SysTaskRecordIssue>lambdaQuery()
                    .eq(SysTaskRecordIssue::getRecordId, recordId)
                    .eq(Objects.nonNull(issuestate), SysTaskRecordIssue::getIssueState, issuestate)
                    .eq(SysTaskRecordIssue::getState, 1)
            );
            if (CollUtil.isNotEmpty(sysTaskRecordIssueList)) {
                List<SysIssueType> recordIssue = new ArrayList<>();
                for (SysTaskRecordIssue sysTaskRecordIssue : sysTaskRecordIssueList) {
                    SysIssueType sysIssueType = sysIssueTypes.stream().filter(v -> StringUtils.equals(v.getId().toString(), sysTaskRecordIssue.getIssueTypeId().toString())).findAny().orElse(null);
                    if (Objects.nonNull(sysIssueType)) {
                        recordIssue.add(sysIssueType);
                    }
                }
                sysTaskRecord.setRecordIssue(recordIssue);
            }
        }
        PageInfo<SysTaskRecord> pageInfo = new PageInfo<SysTaskRecord>(sysTaskRecordList);
        return AjaxResult.success(pageInfo);
    }

    @Override
    public AjaxResult searchUserPatrolRiverRecord(Integer issuestate, Date startTime, Date endTime, String keywords, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<SysTaskRecord> sysTaskRecordList = sysTaskRecordMapper.selectList(Wrappers.<SysTaskRecord>lambdaQuery()
                .eq(SysTaskRecord::getState, 1)
                .ge(ObjectUtil.isNotNull(startTime), SysTaskRecord::getCreateTime, startTime)
                .le(ObjectUtil.isNotNull(endTime), SysTaskRecord::getCreateTime, endTime)
                .like(StrUtil.isNotBlank(keywords), SysTaskRecord::getContent, keywords)
        );

        if (Objects.nonNull(issuestate)) {
            List<Long> recordIdList = sysTaskRecordList.stream().map(SysTaskRecord::getId).collect(Collectors.toList());
            if (CollUtil.isNotEmpty(recordIdList)) {
                List<SysTaskRecordIssue> sysTaskRecordIssues = sysTaskRecordIssueMapper.selectList(Wrappers.<SysTaskRecordIssue>lambdaQuery()
                        .eq(SysTaskRecordIssue::getState, 1)
                        .eq(SysTaskRecordIssue::getIssueState, issuestate)
                        .in(SysTaskRecordIssue::getRecordId, recordIdList)
                );
                Set<Long> recordIdSet = sysTaskRecordIssues.stream().map(SysTaskRecordIssue::getRecordId).collect(Collectors.toSet());
                sysTaskRecordList = sysTaskRecordList.stream().filter(v -> recordIdSet.contains(v)).collect(Collectors.toList());
            }
        }

        List<SysIssueType> sysIssueTypes = sysIssueTypeMapper.selectList(Wrappers.lambdaQuery());
        for (SysTaskRecord sysTaskRecord : sysTaskRecordList) {
            Long recordId = sysTaskRecord.getId();
            List<SysTaskRecordFile> sysTaskRecordFiles = sysTaskRecordFileMapper.selectList(Wrappers.<SysTaskRecordFile>lambdaQuery()
                    .eq(SysTaskRecordFile::getRecordId, recordId)
                    .eq(SysTaskRecordFile::getState, 1)
            );
            List<Long> fileIds = sysTaskRecordFiles.stream().map(SysTaskRecordFile::getId).collect(Collectors.toList());
            if (CollUtil.isNotEmpty(fileIds)) {
                List<SysRes> recordFile = sysResMapper.selectBatchIds(fileIds);
                sysTaskRecord.setRecordFile(recordFile);
            }

            List<SysTaskRecordIssue> sysTaskRecordIssueList = sysTaskRecordIssueMapper.selectList(Wrappers.<SysTaskRecordIssue>lambdaQuery()
                    .eq(SysTaskRecordIssue::getRecordId, recordId)
                    .eq(Objects.nonNull(issuestate), SysTaskRecordIssue::getIssueState, issuestate)
                    .eq(SysTaskRecordIssue::getState, 1)
            );
            if (CollUtil.isNotEmpty(sysTaskRecordIssueList)) {
                List<SysIssueType> recordIssue = new ArrayList<>();
                for (SysTaskRecordIssue sysTaskRecordIssue : sysTaskRecordIssueList) {
                    SysIssueType sysIssueType = sysIssueTypes.stream().filter(v -> StringUtils.equals(v.getId().toString(), sysTaskRecordIssue.getIssueTypeId().toString())).findAny().orElse(null);
                    if (Objects.nonNull(sysIssueType)) {
                        recordIssue.add(sysIssueType);
                    }
                }
                sysTaskRecord.setRecordIssue(recordIssue);
            }
        }
        PageInfo<SysTaskRecord> pageInfo = new PageInfo<SysTaskRecord>(sysTaskRecordList);
        return AjaxResult.success(pageInfo);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public AjaxResult editUserPatrolRiverRecord(EditUserPatrolRiverRecordReq param) {

        if (ObjectUtil.isNull(param.getHasProblem())) {
            return AjaxResult.error("hasProblem不能为空");
        }

        if (param.getHasProblem().intValue() == 0 && CollUtil.isNotEmpty(param.getIssues())) {
            return AjaxResult.error("不存在事件,问题类型必须为空");
        }

        if (param.getHasProblem().intValue() == 1 && CollUtil.isEmpty(param.getIssues())) {
            return AjaxResult.error("存在事件,问题类型不能为空");
        }

        Long recordId = param.getId();
        sysTaskRecordIssueMapper.delete(Wrappers.<SysTaskRecordIssue>lambdaQuery().eq(SysTaskRecordIssue::getRecordId, recordId));
        SysTaskRecordFile recordFile = new SysTaskRecordFile();
        recordFile.setState(0);
        sysTaskRecordFileMapper.update(recordFile, Wrappers.<SysTaskRecordFile>lambdaUpdate().eq(SysTaskRecordFile::getRecordId, recordId));

        Long userId = SecurityUtils.getUserId();
        DateTime now = DateUtil.date();
        SysTaskRecord sysTaskRecord = new SysTaskRecord();
        sysTaskRecord.setId(recordId);
        sysTaskRecord.setTaskId(param.getTaskId());
        sysTaskRecord.setProblem(param.getHasProblem());
        sysTaskRecord.setContent(param.getContent());
        sysTaskRecord.setCreateTime(now);
        sysTaskRecord.setState(1);
        sysTaskRecord.setLatitude(param.getLatitude());
        sysTaskRecord.setLongitude(param.getLongitude());
        sysTaskRecord.setUserId(userId);
        int insert = sysTaskRecordMapper.updateById(sysTaskRecord);

        List<Integer> issues = param.getIssues();
        if (CollUtil.isNotEmpty(issues)) {
            SysTaskRecordIssue sysTaskRecordIssue = null;
            for (Integer issueTypeId : issues) {
                sysTaskRecordIssue = new SysTaskRecordIssue();
                sysTaskRecordIssue.setRecordId(sysTaskRecord.getId());
                sysTaskRecordIssue.setIssueTypeId(issueTypeId);
                sysTaskRecordIssue.setCreateTime(now);
                sysTaskRecordIssue.setState(1);
                sysTaskRecordIssue.setIssueState(0);
                sysTaskRecordIssue.setExamineState(0);
                sysTaskRecordIssueMapper.insert(sysTaskRecordIssue);
            }
        }

        List<Long> files = param.getFiles();
        if (CollUtil.isNotEmpty(files)) {
            SysTaskRecordFile sysTaskRecordFile = null;
            for (Long fileId : files) {
                sysTaskRecordFile = new SysTaskRecordFile();
                sysTaskRecordFile.setState(1);
                sysTaskRecordFile.setCreateTime(now);
                sysTaskRecordFile.setResId(fileId);
                sysTaskRecordFile.setRecordId(sysTaskRecord.getId());
                sysTaskRecordFileMapper.insert(sysTaskRecordFile);
            }
        }

        return AjaxResult.success(SqlHelper.retBool(insert));
    }

    @Override
    @Transactional(rollbackFor = {Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public AjaxResult deleteUserPatrolRiverRecord(DeleteUserPatrolRiverRecordReq param) {
        Long recordId = param.getId();
        sysTaskRecordIssueMapper.delete(Wrappers.<SysTaskRecordIssue>lambdaQuery().eq(SysTaskRecordIssue::getRecordId, recordId));
        SysTaskRecordFile recordFile = new SysTaskRecordFile();
        recordFile.setState(0);
        sysTaskRecordFileMapper.update(recordFile, Wrappers.<SysTaskRecordFile>lambdaUpdate().eq(SysTaskRecordFile::getRecordId, recordId));
        return AjaxResult.success(SqlHelper.retBool(sysTaskRecordMapper.deleteById(recordId)));
    }

    @Override
    public AjaxResult getTaskPatrolRiverRoute(GetTaskPatrolRiverRouteReq param) {
        List<SysTaskRoute> sysTaskRoutes = sysTaskRouteMapper.selectList(Wrappers.<SysTaskRoute>lambdaQuery()
                .eq(SysTaskRoute::getTaskId, param.getTaskId())
        );
        return AjaxResult.success(sysTaskRoutes);
    }

    @Override
    public AjaxResult getMyUserPatrolRiver(GetMyUserPatrolRiverReq param) {

        PageHelper.startPage(param.getPageNum(), param.getPageSize());

        Long userId = SecurityUtils.getUserId();
        List<SysTask> sysTasks = sysTaskMapper.selectList(Wrappers.<SysTask>lambdaQuery()
                .eq(SysTask::getState, 1)
                .eq(Objects.nonNull(param.getFinish()), SysTask::getFinish, param.getFinish())
                .eq(Objects.nonNull(param.getType()), SysTask::getType, param.getType())
                .eq(SysTask::getUserId, userId)
                .ge(ObjectUtil.isNotNull(param.getStartTime()), SysTask::getCreateTime, DateUtils.parseDate(param.getStartTime()))
                .le(ObjectUtil.isNotNull(param.getEndTime()), SysTask::getCreateTime, DateUtils.parseDate(param.getEndTime()))
                .like(StringUtils.isNotBlank(param.getName()), SysTask::getName, param.getName())
                .orderByDesc(SysTask::getCreateTime)
        );

        PageInfo<SysTask> pageInfo = new PageInfo<SysTask>(sysTasks);
        return AjaxResult.success(pageInfo);
    }

    @Override
    public AjaxResult getPatrolRiverTaskDetail(GetPatrolRiverTaskDetailReq param) {
        GetPatrolRiverTaskDetailRes getPatrolRiverTaskDetailRes = new GetPatrolRiverTaskDetailRes();
        SysTask sysTask = getById(param.getTaskId());
        BeanUtils.copyProperties(sysTask, getPatrolRiverTaskDetailRes);
        List<SysTaskRecord> sysTaskRecordList = sysTaskRecordMapper.selectList(Wrappers.<SysTaskRecord>lambdaQuery()
                .eq(SysTaskRecord::getState, 1)
                .eq(SysTaskRecord::getTaskId, param.getTaskId())
        );

        List<SysTaskRoute> sysTaskRoutes = sysTaskRouteMapper.selectList(Wrappers.<SysTaskRoute>lambdaQuery()
                .eq(SysTaskRoute::getTaskId, param.getTaskId())
                .orderByAsc(SysTaskRoute::getSort)
        );
        List<SysIssueType> sysIssueTypes = sysIssueTypeMapper.selectList(Wrappers.lambdaQuery());
        for (SysTaskRecord sysTaskRecord : sysTaskRecordList) {
            Long recordId = sysTaskRecord.getId();
            List<SysTaskRecordFile> sysTaskRecordFiles = sysTaskRecordFileMapper.selectList(Wrappers.<SysTaskRecordFile>lambdaQuery()
                    .eq(SysTaskRecordFile::getRecordId, recordId)
                    .eq(SysTaskRecordFile::getState, 1)
            );
            List<Long> fileIds = sysTaskRecordFiles.stream().map(SysTaskRecordFile::getId).collect(Collectors.toList());
            if (CollUtil.isNotEmpty(fileIds)) {
                List<SysRes> recordFile = sysResMapper.selectBatchIds(fileIds);
                sysTaskRecord.setRecordFile(recordFile);
            }

            List<SysTaskRecordIssue> sysTaskRecordIssueList = sysTaskRecordIssueMapper.selectList(Wrappers.<SysTaskRecordIssue>lambdaQuery()
                    .eq(SysTaskRecordIssue::getRecordId, recordId)
                    .eq(SysTaskRecordIssue::getState, 1)
            );
            List<SysIssueType> recordIssue = new ArrayList<>();
            if (CollUtil.isNotEmpty(sysTaskRecordIssueList)) {
                for (SysTaskRecordIssue sysTaskRecordIssue : sysTaskRecordIssueList) {
                    SysIssueType sysIssueType = sysIssueTypes.stream().filter(v -> StringUtils.equals(v.getId().toString(), sysTaskRecordIssue.getIssueTypeId().toString())).findAny().orElse(null);
                    if (Objects.nonNull(sysIssueType)) {
                        recordIssue.add(sysIssueType);
                    }
                }
            }
            sysTaskRecord.setRecordIssue(recordIssue);
        }

        List<SysTaskPlanroute> sysTaskPlanrouteList = sysTaskPlanrouteMapper.selectList(Wrappers.<SysTaskPlanroute>lambdaQuery().eq(SysTaskPlanroute::getTaskId, param.getTaskId()).orderByAsc(SysTaskPlanroute::getCreateTime));
        for (SysTaskPlanroute sysTaskPlanroute : sysTaskPlanrouteList) {
            SysRoute sysRoute = sysRouteMapper.selectOne(Wrappers.<SysRoute>lambdaQuery().eq(SysRoute::getId, sysTaskPlanroute.getPlanId()));
            if (Objects.nonNull(sysRoute)) {
                List<SysRouteAxes> sysRouteAxesList = sysRouteAxesMapper.selectList(Wrappers.<SysRouteAxes>lambdaQuery().eq(SysRouteAxes::getState, 1).eq(SysRouteAxes::getRoute, sysRoute.getId()));
                sysRoute.setRouteAxesList(sysRouteAxesList);
                sysTaskPlanroute.setSysRoute(sysRoute);
            }
        }
        getPatrolRiverTaskDetailRes.setSysTaskPlanrouteList(sysTaskPlanrouteList);
        getPatrolRiverTaskDetailRes.setSysTaskRecordList(sysTaskRecordList);
        getPatrolRiverTaskDetailRes.setTaskRouteList(sysTaskRoutes);
        return AjaxResult.success(getPatrolRiverTaskDetailRes);
    }


}




